import random

from celery import shared_task
from django.core.cache import cache

from map_backend.settings import EMAIL_HOST_USER
from utils.send_email import send_email


@shared_task
def email_verify_code(userEmail):
    code = random.randint(100000, 999999, )
    cache.set(userEmail, str(code), 60 * 10)
    aa=cache.get(userEmail)
    print(aa)
    content='注册验证码为：{0}，10分钟内有效，请勿泄露和转发。如非本人操作，请忽略此信息。'.format(code)
    subject='WBGOUT马拉松注册'
    send_email(userEmail,subject,content)
    return '发送邮件成功：{0}'.format(userEmail)

@shared_task
def email_error(content):
    # send_mail(
    #     subject='系统报错',
    #     message=content,
    #     from_email=EMAIL_HOST_USER,
    #     recipient_list=['2194482868@qq.com']
    # )
    pass
    # send_mail(
    #     subject='地图系统注册',
    #     message='注册验证码为：{0}，10分钟内有效，请勿泄露和转发。如非本人操作，请忽略此信息。'.format(code),
    #     from_email=EMAIL_HOST_USER,
    #     recipient_list=[userEmail],
    #     fail_silently=False,
    # )